package com.wellgoon.test.leetcode;

/**
 * @Author: Rocky
 * @Date: 2023/4/13
 */
public class DoubleLinkedList<E> {

    int size;

    private DoubleLinkedNode<E> first;

    private DoubleLinkedNode<E> last;

    public void addFirst(E e) {
        DoubleLinkedNode<E> head = first;
        DoubleLinkedNode<E> node = new DoubleLinkedNode<>(null, e, first);
        first = node;
        if (head == null) {
            last = node;
        } else {
            head.prev = node;
        }
        size++;
    }

    public void addLast(E e) {
        DoubleLinkedNode<E> l = last;
        DoubleLinkedNode<E> node = new DoubleLinkedNode<>(l, e, null);
        last = node;
        if (l == null) {
            first = node;
        } else {
            l.next = node;
        }
        size++;
    }

    public void add(E e) {

    }

    private static class DoubleLinkedNode<E> {

        DoubleLinkedNode<E> prev;

        E element;

        DoubleLinkedNode<E> next;

        public DoubleLinkedNode(E element) {
            this.element = element;
        }

        public DoubleLinkedNode(DoubleLinkedNode<E> prev, E element, DoubleLinkedNode<E> next) {
            this.prev = prev;
            this.element = element;
            this.next = next;
        }
    }
}


